<!DOCTYPE html>





<html class="theme-next gemini" lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="generator" content="Hexo 3.9.0">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.3.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/CNY32x32.png?v=7.3.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/CNY16x16.png?v=7.3.0">
  <link rel="mask-icon" href="/images/logo.svg?v=7.3.0" color="#222">

<link rel="stylesheet" href="/css/main.css?v=7.3.0">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.3.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":true},
    save_scroll: false,
    copycode: {"enable":true,"show_result":true,"style":null},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    }
  };
</script>

  <meta name="description" content="前言之前上数据结构这门课的时候，一直没搞明白堆排序到底是为啥就能排序了呢。最近终于弄懂了，其实很简单。  顺便吐槽一下，严蔚敏的紫书代码可读性真滴不咋滴，有了注释也很难知道在说啥，没有就更不用说了，一股浓浓的学究代码气息扑面而来？anyway，先把堆排序这页撕了吧 :)。">
<meta name="keywords" content="数据结构">
<meta property="og:type" content="article">
<meta property="og:title" content="堆排序原来这么简单">
<meta property="og:url" content="localhost:4000/2019/09/21/堆排序原来这么简单/index.html">
<meta property="og:site_name" content="钟浩伟的个人博客">
<meta property="og:description" content="前言之前上数据结构这门课的时候，一直没搞明白堆排序到底是为啥就能排序了呢。最近终于弄懂了，其实很简单。  顺便吐槽一下，严蔚敏的紫书代码可读性真滴不咋滴，有了注释也很难知道在说啥，没有就更不用说了，一股浓浓的学究代码气息扑面而来？anyway，先把堆排序这页撕了吧 :)。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/mmexport1569073823017.jpg!blog">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/tree.png!blog">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/121321313.png!blog">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/asdasdasdqwqwe2131314565.png!blog">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/FHJBSOE.png!blog">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/tree_bulid.png!blog">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/heapsort21354.png!blog">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/asf234rf4vthhhhhhhhhhh.png!blog">
<meta property="og:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/asdsd23o4h235olkfl43.png!blog">
<meta property="og:updated_time" content="2019-09-21T14:09:33.504Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="堆排序原来这么简单">
<meta name="twitter:description" content="前言之前上数据结构这门课的时候，一直没搞明白堆排序到底是为啥就能排序了呢。最近终于弄懂了，其实很简单。  顺便吐槽一下，严蔚敏的紫书代码可读性真滴不咋滴，有了注释也很难知道在说啥，没有就更不用说了，一股浓浓的学究代码气息扑面而来？anyway，先把堆排序这页撕了吧 :)。">
<meta name="twitter:image" content="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/mmexport1569073823017.jpg!blog">
  <link rel="canonical" href="localhost:4000/2019/09/21/堆排序原来这么简单/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>堆排序原来这么简单 | 钟浩伟的个人博客</title>
  








  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  <div class="container sidebar-position-left">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">钟浩伟的个人博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">欢迎光临</p>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-tags">
      
    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-categories">
      
    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger">
        
          <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
      </li>
    
  </ul>

</nav>
  <div class="site-search">
    
  <div class="popup search-popup">
  <div class="search-header">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <div class="search-input-wrapper">
      <input autocomplete="off" autocorrect="off" autocapitalize="none"
             placeholder="搜索..." spellcheck="false"
             type="text" id="search-input">
    </div>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>
  <div id="search-result"></div>
</div>


  </div>
</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
            

          <div id="content" class="content page-post-detail">
            

  <div id="posts" class="posts-expand">
    

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="localhost:4000/2019/09/21/堆排序原来这么简单/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="钟浩伟">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/profile.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="钟浩伟的个人博客">
    </span>
      <header class="post-header">

        
          <h1 class="post-title" itemprop="name headline">堆排序原来这么简单

            
          </h1>
        

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-09-21 20:17:41" itemprop="dateCreated datePublished" datetime="2019-09-21T20:17:41+08:00">2019-09-21</time>
            </span>
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/计算机理论/" itemprop="url" rel="index"><span itemprop="name">计算机理论</span></a></span>

                
                
              
            </span>
          

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>之前上数据结构这门课的时候，一直没搞明白堆排序到底是为啥就能排序了呢。最近终于弄懂了，其实很简单。</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/mmexport1569073823017.jpg!blog" alt="mmexport1569073823017"></p>
<p>顺便吐槽一下，严蔚敏的紫书代码可读性真滴不咋滴，有了注释也很难知道在说啥，没有就更不用说了，一股浓浓的学究代码气息扑面而来？anyway，先把堆排序这页撕了吧 :)。</p>
<a id="more"></a>

<h1 id="堆排序的前提"><a href="#堆排序的前提" class="headerlink" title="堆排序的前提"></a>堆排序的前提</h1><h2 id="堆要符合什么条件"><a href="#堆要符合什么条件" class="headerlink" title="堆要符合什么条件"></a>堆要符合什么条件</h2><ol>
<li>堆排序的堆是完全二叉树，因此用<strong>数组</strong>实现是最好的（因为完全二叉树的节点是连续的）</li>
<li>父节点比子节点大，或父节点比子节点小</li>
</ol>
<h2 id="获取父子节点"><a href="#获取父子节点" class="headerlink" title="获取父子节点"></a>获取父子节点</h2><p>易观察并总结出规律得：</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/tree.png!blog" alt="tree"></p>
<h3 id="获取子节点的公式"><a href="#获取子节点的公式" class="headerlink" title="获取子节点的公式"></a>获取子节点的公式</h3><p>c1 = 2n+1</p>
<p>c2 = 2n+2</p>
<h3 id="获取父节点公式"><a href="#获取父节点公式" class="headerlink" title="获取父节点公式"></a>获取父节点公式</h3><p>p = (c+1)/2</p>
<h1 id="说在前面"><a href="#说在前面" class="headerlink" title="说在前面"></a>说在前面</h1><p>别急，在进行真正的堆排序之前，不妨先实现两个操作，堆调整和创建堆，他们都是堆排序所必需的操作。</p>
<h1 id="调整堆"><a href="#调整堆" class="headerlink" title="调整堆"></a>调整堆</h1><p>为了保持每个父节点对于其子节点之间的大小关系，需要进行堆的调整</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/121321313.png!blog" alt="121321313"></p>
<p>假设我现在是大根堆，就是父节点要比子节点大，具体调整办法就是，求出父节点的子节点，然后进行比较，把最大的那个节点与父节点进行交换，因为发生了交换，所以原来的子节点与他的子节点的关系可能发生了变化，所以还要对子节点进行堆调整</p>
<p>举个例子</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/asdasdasdqwqwe2131314565.png!blog" alt="asdasdasdqwqwe2131314565"></p>
<p>框框圈住的地方需要调整堆，于是与其子节点12、7进行比较发现12号子节点最大，于是交换上去，12号发生了交换所以，12号和其子节点7、8号也需要进行调整堆。这样就保持了堆的数据特性</p>
<p>上代码，看得更清楚</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//调整堆</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">heapify</span><span class="params">(<span class="keyword">int</span> tree[],<span class="keyword">int</span> n,<span class="keyword">int</span> i)</span></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(i &gt;= n)&#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">int</span> c1 = <span class="number">2</span>*i + <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">int</span> c2 = <span class="number">2</span>*i + <span class="number">2</span>;</span><br><span class="line">    <span class="keyword">int</span> max = i;</span><br><span class="line">    <span class="keyword">if</span>(c1 &lt; n &amp;&amp; tree[c1] &gt; tree[max])&#123;</span><br><span class="line">        max = c1;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(c2 &lt; n &amp;&amp; tree[c2] &gt; tree[max])&#123;</span><br><span class="line">        max = c2;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(max != i)&#123;</span><br><span class="line">        swap(tree,i,max);</span><br><span class="line">        heapify(tree,n,max);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="创建堆"><a href="#创建堆" class="headerlink" title="创建堆"></a>创建堆</h1><p>however，通常情况是，给你的数完全不符合堆的结构，然后不知道该从哪开始调整堆了。莫慌，从h-1层的最左边的节点开始逐步调整即可。这样就能把每个红框框圈起来的父子节点们都进行了一边堆调整了哦，使得树的结构符合堆的要求</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/FHJBSOE.png!blog" alt="FHJBSOE"></p>
<p>h-1的阶段序号怎么求？easy，求最后一个的节点的父节点就是了嘛</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/tree_bulid.png!blog" alt="tree_bulid"></p>
<p>如图所示，从3号节点开始，然后2号，1号，0号。没错，你也发现了！ 其实就是一个递减的关系 3,2,1,0这样在遍历的时候就很容易了。</p>
<p>上代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//创建堆</span></span><br><span class="line"><span class="comment">//从h-1层的最左边的节点开始调整</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">build_heap</span><span class="params">(<span class="keyword">int</span> tree[],<span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> last_node = n - <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">int</span> parent = (last_node - <span class="number">1</span>)/ <span class="number">2</span> ;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=parent;i &gt;=<span class="number">0</span>;i--)&#123;</span><br><span class="line">        heapify(tree,n,i);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="堆排序"><a href="#堆排序" class="headerlink" title="堆排序"></a>堆排序</h1><p>好了，现在随便给你一串序列，你都能通过<code>build_heap</code>构造大根堆了</p>
<p>例如：</p>
<p>输入：</p>
<p>{4,10,3,5,1,2,9,6,13}</p>
<p>输出：</p>
<p>{13,10,9,6,1,2,3,4,5}</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/heapsort21354.png!blog" alt="heapsort21354"></p>
<p>堆排序的过程如下：</p>
<p>因为可以发现整个树的根节点就是最大值，所以直接将最后一个节点与第一个节点交换，然后“斩断”最后一个节点。然后对新的根节点进行堆调整。</p>
<p>“斩断”的节点就是当前的最大值，随便你怎么搞，输出也好，放在队列中也好，放在栈中也好。</p>
<p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/asf234rf4vthhhhhhhhhhh.png!blog" alt="asf234rf4vthhhhhhhhhhh"></p>
<p>这样你就可以又得到一颗去除了最大值的堆了~~，重复此过程直到树中没有树了或者遍历到头了（其实是懒得作图了- - ）。就完成了堆排序了哦。</p>
<p>上代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//堆排序，升序</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">heap_sort</span><span class="params">(<span class="keyword">int</span> tree[],<span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">    build_heap(tree,n);</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=n<span class="number">-1</span>;i&gt;=<span class="number">0</span>;i--)&#123;</span><br><span class="line">        <span class="comment">//最后一个与根节点进行交换</span></span><br><span class="line">        swap(tree,i,<span class="number">0</span>);</span><br><span class="line">        <span class="comment">//调整根节点，注意此时的第二个参数也就是处理的数组大小变成了i哦，相当于斩断了最后一个节点</span></span><br><span class="line">        heapify(tree,i,<span class="number">0</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h2><p><img src="https://zhong-blog.oss-cn-shenzhen.aliyuncs.com/blog/asdsd23o4h235olkfl43.png!blog" alt="asdsd23o4h235olkfl43"></p>
<h1 id="完整代码（C语言）"><a href="#完整代码（C语言）" class="headerlink" title="完整代码（C语言）"></a>完整代码（C语言）</h1><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdlib.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">swap</span><span class="params">(<span class="keyword">int</span> tree[],<span class="keyword">int</span> i,<span class="keyword">int</span> j)</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> tmp = tree[i];</span><br><span class="line">    tree[i] = tree[j];</span><br><span class="line">    tree[j] = tmp;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//调整堆</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">heapify</span><span class="params">(<span class="keyword">int</span> tree[],<span class="keyword">int</span> n,<span class="keyword">int</span> i)</span></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(i &gt;= n)&#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">int</span> c1 = <span class="number">2</span>*i + <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">int</span> c2 = <span class="number">2</span>*i + <span class="number">2</span>;</span><br><span class="line">    <span class="keyword">int</span> max = i;</span><br><span class="line">    <span class="keyword">if</span>(c1 &lt; n &amp;&amp; tree[c1] &gt; tree[max])&#123;</span><br><span class="line">        max = c1;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(c2 &lt; n &amp;&amp; tree[c2] &gt; tree[max])&#123;</span><br><span class="line">        max = c2;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(max != i)&#123;</span><br><span class="line">        swap(tree,i,max);</span><br><span class="line">        heapify(tree,n,max);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//创建堆</span></span><br><span class="line"><span class="comment">//从h-1层的最左边的节点开始调整</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">build_heap</span><span class="params">(<span class="keyword">int</span> tree[],<span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> last_node = n - <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">int</span> parent = (last_node - <span class="number">1</span>)/ <span class="number">2</span> ;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=parent;i &gt;=<span class="number">0</span>;i--)&#123;</span><br><span class="line">        heapify(tree,n,i);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//堆排序，升序</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">heap_sort</span><span class="params">(<span class="keyword">int</span> tree[],<span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">    build_heap(tree,n);</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=n<span class="number">-1</span>;i&gt;=<span class="number">0</span>;i--)&#123;</span><br><span class="line">        <span class="comment">//最后一个与根节点进行交换</span></span><br><span class="line">        swap(tree,i,<span class="number">0</span>);</span><br><span class="line">        <span class="comment">//调整根节点，注意此时的第二个参数也就是处理的数组大小变成了i哦，相当于斩断了最后一个节点</span></span><br><span class="line">        heapify(tree,i,<span class="number">0</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> tree[] = &#123;<span class="number">4</span>,<span class="number">10</span>,<span class="number">3</span>,<span class="number">5</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">9</span>,<span class="number">6</span>,<span class="number">13</span>&#125;;</span><br><span class="line">    <span class="keyword">int</span> n = <span class="number">9</span>;</span><br><span class="line">    heap_sort(tree,n);</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;n;i++)&#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">"%d "</span>,tree[i]);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<pre><code>1 2 3 4 5 6 9 10 13 </code></pre><h1 id="完整代码（Python）"><a href="#完整代码（Python）" class="headerlink" title="完整代码（Python）"></a>完整代码（Python）</h1><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># coding:utf-8</span></span><br><span class="line"><span class="comment"># 交换数据元素</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">swap</span><span class="params">(tree, i, j)</span>:</span></span><br><span class="line">    temp = tree[i]</span><br><span class="line">    tree[i] = tree[j]</span><br><span class="line">    tree[j] = temp</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"><span class="comment"># 调整堆，调整为大根堆</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">heapify</span><span class="params">(tree, i)</span>:</span></span><br><span class="line">    <span class="keyword">if</span> i &gt;= len(tree):</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    c1 = <span class="number">2</span> * i + <span class="number">1</span></span><br><span class="line">    c2 = <span class="number">2</span> * i + <span class="number">2</span></span><br><span class="line">    max = i</span><br><span class="line">    <span class="keyword">if</span> c1 &lt; len(tree) <span class="keyword">and</span> tree[c1] &gt; tree[max]:</span><br><span class="line">        max = c1</span><br><span class="line">    <span class="keyword">if</span> c2 &lt; len(tree) <span class="keyword">and</span> tree[c2] &gt; tree[max]:</span><br><span class="line">        max = c2</span><br><span class="line">    <span class="keyword">if</span> max != i:</span><br><span class="line">        swap(tree, max, i)</span><br><span class="line">        heapify(tree, max)</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"><span class="comment"># 构造堆</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">build_heap</span><span class="params">(tree)</span>:</span></span><br><span class="line">    last_node = len(tree) - <span class="number">1</span></span><br><span class="line">    parent = int((last_node - <span class="number">1</span>) / <span class="number">2</span>)</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(parent, <span class="number">-1</span>, <span class="number">-1</span>):</span><br><span class="line">        heapify(tree, i)</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"><span class="comment"># 堆排序.大根堆，降序</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">heap_sort</span><span class="params">(tree)</span>:</span></span><br><span class="line">    build_heap(tree)</span><br><span class="line">    result = []</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(len(tree) - <span class="number">1</span>, <span class="number">-1</span>, <span class="number">-1</span>):</span><br><span class="line">        <span class="comment"># 交换根节点与最后一个节点,砍断最后一个节点，重新调整堆</span></span><br><span class="line">        swap(tree, i, <span class="number">0</span>)</span><br><span class="line">        result.append(tree.pop())</span><br><span class="line">        heapify(tree, <span class="number">0</span>)</span><br><span class="line">    <span class="keyword">return</span> result</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"><span class="comment"># 调整堆，调整为小根堆</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">heapify1</span><span class="params">(tree, i)</span>:</span></span><br><span class="line">    <span class="keyword">if</span> i &gt;= len(tree):</span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    c1 = <span class="number">2</span> * i + <span class="number">1</span></span><br><span class="line">    c2 = <span class="number">2</span> * i + <span class="number">2</span></span><br><span class="line">    min = i</span><br><span class="line">    <span class="keyword">if</span> c1 &lt; len(tree) <span class="keyword">and</span> tree[c1] &lt; tree[min]:</span><br><span class="line">        min = c1</span><br><span class="line">    <span class="keyword">if</span> c2 &lt; len(tree) <span class="keyword">and</span> tree[c2] &lt; tree[min]:</span><br><span class="line">        min = c2</span><br><span class="line">    <span class="keyword">if</span> min != i:</span><br><span class="line">        swap(tree, min, i)</span><br><span class="line">        heapify(tree, min)</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"><span class="comment"># 构造小根堆</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">build_heap1</span><span class="params">(tree)</span>:</span></span><br><span class="line">    last_node = len(tree) - <span class="number">1</span></span><br><span class="line">    parent = int((last_node - <span class="number">1</span>) / <span class="number">2</span>)</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(parent, <span class="number">-1</span>, <span class="number">-1</span>):</span><br><span class="line">        heapify1(tree, i)</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"><span class="comment"># 堆排序.小根堆，升序</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">heap_sort1</span><span class="params">(tree)</span>:</span></span><br><span class="line">    build_heap1(tree)</span><br><span class="line">    result = []</span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> range(len(tree) - <span class="number">1</span>, <span class="number">-1</span>, <span class="number">-1</span>):</span><br><span class="line">        <span class="comment"># 交换根节点与最后一个节点,砍断最后一个节点，重新调整堆</span></span><br><span class="line">        swap(tree, i, <span class="number">0</span>)</span><br><span class="line">        result.append(tree.pop())</span><br><span class="line">        heapify1(tree, <span class="number">0</span>)</span><br><span class="line">    <span class="keyword">return</span> result</span><br><span class="line"> </span><br><span class="line"> </span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:</span><br><span class="line">    tree = [<span class="number">2</span>, <span class="number">5</span>, <span class="number">3</span>, <span class="number">1</span>, <span class="number">10</span>, <span class="number">4</span>]</span><br><span class="line">    print(<span class="string">"原始数据："</span>)</span><br><span class="line">    print(tree)</span><br><span class="line">    result = heap_sort(tree)</span><br><span class="line">    print(<span class="string">"大根堆排序："</span>)</span><br><span class="line">    print(result)</span><br><span class="line"> </span><br><span class="line">    <span class="comment"># 小根堆测试用例</span></span><br><span class="line">    tree = [<span class="number">345</span>, <span class="number">312</span>, <span class="number">65</span>, <span class="number">765</span>, <span class="number">143</span>, <span class="number">564</span>]</span><br><span class="line">    print(<span class="string">"原始数据："</span>)</span><br><span class="line">    print(tree)</span><br><span class="line">    result = heap_sort1(tree)</span><br><span class="line">    print(<span class="string">"小根堆排序："</span>)</span><br><span class="line">    print(result)</span><br></pre></td></tr></table></figure>

<pre><code>原始数据：
[2, 5, 3, 1, 10, 4]
大根堆排序：
[10, 5, 4, 3, 2, 1]
原始数据：
[345, 312, 65, 765, 143, 564]
小根堆排序：
[65, 143, 312, 345, 564, 765]</code></pre>
    </div>

    
    
    
      
  <div class="popular-posts-header">相关文章推荐</div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2019\09\03\AOE网及关键路径\" rel="bookmark">AOE网及关键路径实现</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2019\09\03\图的遍历-BFS和DFS\" rel="bookmark">图的遍历:BFS和DFS</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2019\09\02\图的存储结构实现：邻接表\" rel="bookmark">图的存储结构实现：邻接表</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2019\09\03\拓扑排序及实现\" rel="bookmark">拓扑排序及实现</a></div>
      
    </li>
  
    <li class="popular-posts-item">
      
      
      <div class="popular-posts-title"><a href="\2019\09\03\最小生成树-Prim算法实现\" rel="bookmark">最小生成树:Prim算法实现</a></div>
      
    </li>
  
  </ul>


    
    <div>
      
      <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束感谢您的阅读,如有疑问，请联系<a href="mailto:610596547@qq.com">610596547@qq.com</a>-------------</div>
    
</div>
      
    </div>
        
      

      <footer class="post-footer">
          
            
          
          <div class="post-tags">
            
              <a href="/tags/数据结构/" rel="tag"># 数据结构</a>
            
          </div>
        

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
              
                <a href="/2019/09/09/编程珠玑：位排序/" rel="next" title="编程珠玑：位排序（Python实现）">
                  <i class="fa fa-chevron-left"></i> 编程珠玑：位排序（Python实现）
                </a>
              
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
              
                <a href="/2019/12/26/Spring Cloud笔记/" rel="prev" title="Spirng Cloud学习笔记">
                  Spirng Cloud学习笔记 <i class="fa fa-chevron-right"></i>
                </a>
              
            </div>
          </div>
        
      </footer>
    
  </div>
  
  
  
  </article>

  </div>


          </div>
          

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">

          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
      src="/images/profile.jpg"
      alt="钟浩伟">
  <p class="site-author-name" itemprop="name">钟浩伟</p>
  <div class="site-description motion-element" itemprop="description"></div>
</div>
  <nav class="site-state motion-element">
      <div class="site-state-item site-state-posts">
        
          <a href="/archives/">
        
          <span class="site-state-item-count">44</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/categories/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/tags/">
          
        
        
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://github.com/XiaoZhong233" title="GitHub &rarr; https://github.com/XiaoZhong233" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="mailto:601596547@qq.com" title="E-Mail &rarr; mailto:601596547@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://blog.csdn.net/weixin_41154636" title="CSDN &rarr; https://blog.csdn.net/weixin_41154636" rel="noopener" target="_blank"><i class="fa fa-fw fa-book"></i>CSDN</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="http://profile.zhonghaowei.xyz/" title="Profile &rarr; http://profile.zhonghaowei.xyz/" rel="noopener" target="_blank"><i class="fa fa-fw fa-address-card-o"></i>Profile</a>
      </span>
    
  </div>



        </div>
      </div>
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#堆排序的前提"><span class="nav-number">2.</span> <span class="nav-text">堆排序的前提</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#堆要符合什么条件"><span class="nav-number">2.1.</span> <span class="nav-text">堆要符合什么条件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#获取父子节点"><span class="nav-number">2.2.</span> <span class="nav-text">获取父子节点</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#获取子节点的公式"><span class="nav-number">2.2.1.</span> <span class="nav-text">获取子节点的公式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#获取父节点公式"><span class="nav-number">2.2.2.</span> <span class="nav-text">获取父节点公式</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#说在前面"><span class="nav-number">3.</span> <span class="nav-text">说在前面</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#调整堆"><span class="nav-number">4.</span> <span class="nav-text">调整堆</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#创建堆"><span class="nav-number">5.</span> <span class="nav-text">创建堆</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#堆排序"><span class="nav-number">6.</span> <span class="nav-text">堆排序</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#测试"><span class="nav-number">6.1.</span> <span class="nav-text">测试</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#完整代码（C语言）"><span class="nav-number">7.</span> <span class="nav-text">完整代码（C语言）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#完整代码（Python）"><span class="nav-number">8.</span> <span class="nav-text">完整代码（Python）</span></a></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      



    </div>
  </aside>
  <div id="sidebar-dimmer"></div>




      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">钟浩伟</span>
</div>


<div id="days"></div>
<div class="BbeiAn-info">
   	粤ICP备 -
    <a target="_blank" href="http://beian.miit.gov.cn" style="color:#f0d784"  rel="nofollow">粤ICP备19111001号-1</a> <!--a标签中增加nofollow属性，避免爬虫出站。-->| 
	<a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=" style="color:#f0d784;text-decoration:none;padding-left:30px;background:url(https://s1.ax1x.com/2018/09/29/ilmwIH.png) no-repeat left center" rel="nofollow">粤公网安备 粤ICP备19111001号-1</a>	  <!--这里将图标作为了背景，以使得能和后面的文字在同一行-->
</div>

<script>
function show_date_time(){
    window.setTimeout("show_date_time()", 1000);
    BirthDay=new Date("08/15/2019 22:40:14");
    today=new Date();
    timeold=(today.getTime()-BirthDay.getTime());
    sectimeold=timeold/1000
    secondsold=Math.floor(sectimeold);
    msPerDay=24*60*60*1000
    e_daysold=timeold/msPerDay
    daysold=Math.floor(e_daysold);
    e_hrsold=(e_daysold-daysold)*24;
    hrsold=setzero(Math.floor(e_hrsold));
    e_minsold=(e_hrsold-hrsold)*60;
    minsold=setzero(Math.floor((e_hrsold-hrsold)*60));
    seconds=setzero(Math.floor((e_minsold-minsold)*60));
    document.getElementById('days').innerHTML="<p>小破站已运行 "+daysold+" 天 "+hrsold+" 小时 "+minsold+" 分 "+seconds+" 秒</p>";
}
function setzero(i) {
    if (i<10) {
        i="0" + i
    };
    return i;
}
show_date_time();
</script>

        








        
      </div>
    </footer>
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>

    

  </div>

  
  <script src="/lib/jquery/index.js?v=3.4.1"></script>

<script src="/js/utils.js?v=7.3.0"></script>

<script src="/js/schemes/pisces.js?v=7.3.0"></script>



<script src="/js/next-boot.js?v=7.3.0"></script>




  















  <script src="/js/local-search.js?v=7.3.0"></script>










<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme: 'default',
      logLevel: 3,
      flowchart: { curve: 'linear' },
      gantt: { axisFormat: '%m/%d/%Y' },
      sequence: { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>




  

  

  


  
  <script src="/js/scrollspy.js?v=7.3.0"></script>
<script src="/js/post-details.js?v=7.3.0"></script>



  
  <script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
  
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/assets/hijiki.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":false}});</script></body>
</html>
